package com.classic.okhttp.defer;


import com.classic.okhttp.crypt.CryptType;
import com.classic.okhttp.defer.impl.DeferSecret;
import com.classic.okhttp.json.JSONAndroidFactoryImpl;
import com.classic.okhttp.json.me.JSONFactory;

/**
 * @author Rockey
 */
public final class CoreDeferObject
{

    private static final CoreDeferObject DEFER = new CoreDeferObject();
    private DeferMD5 deferMD5;
    private JSONFactory jsonFactory;
    private DeferBase64 deferBase64;

    public DeferSecret[] getSecs() {
        return secs;
    }

    public DeferSecret getSec(CryptType type) {
        if(type == CryptType.UNKNOW)
            return null;
        for(DeferSecret d : secs)
        {
           if(d.getClass().getName().equals(type.className))
           {
               return d;
           }

        }
        return null;
    }

    private DeferSecret[] secs;

    public static CoreDeferObject get()
    {
        return DEFER;
    }

    private CoreDeferObject()
    {
        jsonFactory=new JSONAndroidFactoryImpl();
        deferBase64=new DeferBase64Imp();
        // This constructor is intentionally empty.
    }

    public DeferMD5 getDeferMD5()
    {
        return deferMD5;
    }

    public void setDeferMD5(final DeferMD5 deferMD5)
    {
        this.deferMD5 = deferMD5;
    }

    public boolean isMd5UtilRegistered()
    {
        return null != getDeferMD5();
    }

    public JSONFactory getJsonFactory()
    {
        return jsonFactory;
    }

    public void setJsonFactory(final JSONFactory jsonFactory)
    {
        this.jsonFactory = jsonFactory;
    }

    public boolean isJsonFactoryRegistered()
    {
        return null != getJsonFactory();
    }

	public DeferBase64 getDeferBase64() {
		return deferBase64;
	}

	public void registerDeferBase64(DeferBase64 deferBase64) {
		this.deferBase64 = deferBase64;
	}

	public boolean isRegisterDeferBase64() {
		return null != deferBase64;
	}

    public void registSecret(DeferSecret   ...secs)
    {
         this.secs = secs;
    }

}
